package com.kolalo.comm;

import java.util.Stack;

public class StackUtil {
    public static boolean isInputEnd(String input) throws Exception {
        Stack<Character> stack=new Stack<Character>();
        for (int i = 0; i < input.length(); i++) {
            Character c=input.charAt(i);
            switch (c) {
                case '{':
                case '(':
                    stack.push(c);
                    break;
                case '}':
                    if(stack.empty())throw new Exception("More than a '}'");
                    if(!stack.pop().equals('{')) throw new Exception("The lack of '{'");
                    break;
                case ')':
                    if(stack.empty())throw new Exception("More than a ')'");
                    if(!stack.pop().equals('(')) throw new Exception("The lack of '('");
                    break;
                default:
                    break;
            }
        }
        return stack.empty();
    }
}
